import React , {Component} from 'react';
import { Route, Redirect, Switch } from 'react-router-dom';
import DocumentTitle from 'react-document-title';
import AllComponents from '../components'
import routesConfig from './config'
//Object.key 返回一个数组 , 成员是参数的key
//Array.map(function) 将Array中的每一项用function处理， 返回新数组  
class CRouter extends Component{
    
    render(){
        return(
            <Switch>
                {Object.keys(routesConfig).map(key =>       //menus[],others[]
                    routesConfig[key].map(r => {      //    {key:'/app/dashboard/index',title:'首页',icone:'mobile',component: 'Dashboard'} ...    
                        const route = r => {
                            const Component = AllComponents[r.component];
                          //  console.log(Component)
                            return(
                                <Route 
                                    key={r.route || r.key}
                                    exact
                                    path={r.route || r.key}
                                    component = {Component}
                                    // render = {

                                    // }
                                />
                            )
                        }
                        return  route(r)
                    })
                )}
            </Switch>
        )
    }
}

export default CRouter